package cpu.footprint.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.squareup.picasso.Picasso;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import cpu.footprint.R;
import cpu.footprint.api.ApiUrl;
import cpu.footprint.common.BaseActivity;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * 查看大图界面
 * Created by Administrator on 2017/5/18.
 */
@ContentView(R.layout.activity_image)
public class ImageActivity extends Activity {
    // 大图
    @ViewInject(R.id.image_view)
    private PhotoView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        String srcUrl = ApiUrl.URL_HOST+getIntent().getStringExtra("imageName");
        PhotoViewAttacher attacher = new PhotoViewAttacher(imageView);
        if (!srcUrl.isEmpty())
            Picasso.with(ImageActivity.this).load(srcUrl).into(imageView);
        //创建一个photoview的一个attacher
        attacher.update();
    }
    @Event(value = {R.id.back_view1,R.id.back_view2,R.id.image_left})
    private void OnClick(View v) {
        switch (v.getId()) {
            case R.id.back_view1:
            case R.id.image_left:
            case R.id.back_view2: {
                this.finish();
                overridePendingTransition(0,R.anim.fade);
                break;
            }
            default:
                break;
        }
    }
    /**
     * 重写后退函数
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            ImageActivity.this.finish();
            overridePendingTransition(0,R.anim.fade);
            return true;
        } else
            return super.onKeyDown(keyCode, event);
    }
}
